
<template>
	<!-- 添加弹框 -->
	<el-dialog title="" size=''   :visible.sync="dialogTableVisible" class="wrap" @close="cancel" :close-on-click-modal="false">
		<i class="el-icon-close close" @click="cancel" style="color: white;z-index:10;"></i>
	    <div class="bt">添加排课</div>
		<el-form label-width="100px" class="form">
		<el-collapse v-model="activeNames" >
		<el-collapse-item title="基本信息" name="1">
			<el-form-item label="班级">
				<el-select v-model="vbjid" class="select-block" @change="getlslist">
							<el-option :label="v.mc" :value="v.id" v-for="v in bjboxlist"></el-option>
				</el-select>
			</el-form-item>

			<el-form-item label="老师">
					<!-- <el-select v-model="vlsid" class="select-block" >
								<el-option :label="v.mc" :value="v.id" v-for="v in lsboxlist"></el-option>
					</el-select> -->
					<el-input v-model="vzwm" class="select-block"  icon="add" ></el-input>
			</el-form-item>

			<el-form-item label="教室">
				<el-select v-model="vjsid" class="select-block" @change="getsjdlist">
							<el-option :label="v.jsmc" :value="v.id " v-for="v in jsboxlist"></el-option>
				</el-select>
			</el-form-item>
 			</el-collapse-item>

 			<el-collapse-item title="课程安排" name="1">
				<el-form-item label="开始时间">
					<el-date-picker class="select-block"  v-model="vkssj"  type="date"  placeholder="选择日期"  ></el-date-picker>
				</el-form-item>
				<el-form-item label="课时数量">
					<el-input v-model="vkssl" placeholder="请输入课时数量" icon="add" class="select-block"></el-input>
				</el-form-item>
				<!-- <el-checkbox-group v-model="vsjdid"  >
						<el-checkbox v-for="city in sjdboxlist" :label="city.id" >{{city.sjd}}</el-checkbox>
				</el-checkbox-group> -->
				</el-form-item>
				<span>上课周期</span>
				<el-checkbox-group v-model="checkList"  >
					<el-checkbox class="check" label="1">星期一</el-checkbox>
					<el-checkbox-group v-model="vsjdid1"  >
							<el-checkbox v-for="city in sjdboxlist" :label="city.id" >{{city.sjd}}</el-checkbox>
					</el-checkbox-group>
					<el-checkbox class="check" label="2">星期二</el-checkbox>
					<el-checkbox-group v-model="vsjdid2"  >
							<el-checkbox v-for="city in sjdboxlist" :label="city.id" >{{city.sjd}}</el-checkbox>
					</el-checkbox-group>
					<el-checkbox class="check" label="3">星期三</el-checkbox>
					<el-checkbox-group v-model="vsjdid3"  >
							<el-checkbox v-for="city in sjdboxlist" :label="city.id" >{{city.sjd}}</el-checkbox>
					</el-checkbox-group>
					<el-checkbox class="check" label="4">星期四</el-checkbox>
					<el-checkbox-group v-model="vsjdid4"  >
							<el-checkbox v-for="city in sjdboxlist" :label="city.id" >{{city.sjd}}</el-checkbox>
					</el-checkbox-group>
					<el-checkbox class="check" label="5">星期五</el-checkbox>
					<el-checkbox-group v-model="vsjdid5"  >
							<el-checkbox v-for="city in sjdboxlist" :label="city.id" >{{city.sjd}}</el-checkbox>
					</el-checkbox-group>
					<el-checkbox class="check" label="6">星期六</el-checkbox>
					<el-checkbox-group v-model="vsjdid6"  >
							<el-checkbox v-for="city in sjdboxlist" :label="city.id" >{{city.sjd}}</el-checkbox>
					</el-checkbox-group>
					<el-checkbox class="check" label="0">星期日</el-checkbox>
					<el-checkbox-group v-model="vsjdid7"  >
							<el-checkbox v-for="city in sjdboxlist" :label="city.id" >{{city.sjd}}</el-checkbox>
					</el-checkbox-group>
				</el-checkbox-group>

 		    </el-collapse-item>
 		</el-collapse>
 	</el-form>
	<el-button type="primary" class="submit" @click="submit">保存</el-button>
	</el-dialog>
</template>
<script type="text/javascript">
	import qs from 'qs'
	export default {
		data() {
			return {
				checkList:[],
				bjboxlist:[],
				jsboxlist:[],
				sjdList:[],
				sjdboxlist:[],
				vbjid:'',
				vjsid:'',
				vkssl:'',
				vkssj:'',
				vsjdid1: [],
				vsjdid2: [],
				vsjdid3: [],
				vsjdid4: [],
				vsjdid5: [],
				vsjdid6: [],
				vsjdid7: [],
				vzwm:'',

				activeNames:'1',
				ysbjid:this.$route.query.iid,
				dialogTableVisible: true,
				xsid:'',
				xszwm:'',
			}
		},
		created () {
			this.getbjlist()
			this.getjslist();
		},
		methods: {
			getbjlist(){
				var logininfo = JSON.parse(localStorage.logininfo);
              this.searchLoading = true;
             var params2 = qs.stringify({
                     yhid: logininfo.id + '',
								xxid: logininfo.xxid + ''
               })
             //执行
                 this.axios.post(this.$store.state.api + 'bj/getbj',  params2 )
                 .then(res => {
                 console.log(res)
							let data = res.data.data.list;
							this.bjboxlist = data;
                 }).catch(res => {
				})
				
				
				
				
				
				
//				var logininfo = JSON.parse(localStorage.logininfo) ;
//					this.axios.get(this.$store.state.api + 'bj/getbj',{
//						params: {
//								yhid: logininfo.id + '',
//								xxid: logininfo.xxid + ''
//						}
//					}).then( res => {
//						// console.log(1212)
//						console.log(res)
//							let data = res.data.data.list;
//							this.bjboxlist = data;
//					}).catch( res => {
//					})
			},
			getlslist(){
				var logininfo = JSON.parse(localStorage.logininfo);
              this.searchLoading = true;
             var params2 = qs.stringify({
                     bjid:this.vbjid
               })
             //执行
                 this.axios.post(this.$store.state.api + 'bj/lsbj',  params2 )
                 .then(res => {
                 console.log(res)
							let data = res.data.data.list;
							this.vzwm = data[0].zwm;
							this.vlsid = data[0].lsid;
							console.log(this.vzwm)
                 }).catch(res => {
				})
//				var logininfo = JSON.parse(localStorage.logininfo) ;
//					this.axios.get(this.$store.state.api + 'bj/lsbj',{
//						params: {
//								bjid:this.vbjid
//						}
//					}).then( res => {
//						// console.log(1212)
//						console.log(res)
//							let data = res.data.data.list;
//							this.vzwm = data[0].zwm;
//							this.vlsid = data[0].lsid;
//							console.log(this.vzwm)
//					}).catch( res => {
//					})
			},
			getjslist(){
				var logininfo = JSON.parse(localStorage.logininfo);
              this.searchLoading = true;
             var params2 = qs.stringify({
                     xxid:logininfo.xxid
               })
             //执行
                 this.axios.post(this.$store.state.api + 'xxjs/mc',  params2 )
                 .then(res => {
                 console.log(res)
							console.log(1)
							console.log(res)
							let data = res.data.data;
							this.jsboxlist = data;
                 }).catch(res => {
				})
				
				
				
				
				
//				var logininfo = JSON.parse(localStorage.logininfo) ;
//					// this.searchLoading = true;
//					this.axios.get(this.$store.state.api + 'xxjs/mc',{
//						params: {
//								xxid:logininfo.xxid
//						}
//					}).then( res => {
//						console.log(1)
//							console.log(res)
//							let data = res.data.data;
//							this.jsboxlist = data;
//					}).catch( res => {
//					})
			},
			getsjdlist(){
				var logininfo = JSON.parse(localStorage.logininfo);
              this.searchLoading = true;
             var params2 = qs.stringify({
                     jsid:this.vjsid
               })
             //执行
                 this.axios.post(this.$store.state.api + 'jssjd/mc',  params2 )
                 .then(res => {
                 console.log(res)
							console.log(12)
							console.log(res)
							// this.sjdboxlist = res;
							let data = res.data.data;
							this.sjdboxlist = data;
                 }).catch(res => {
				})
				
				
				
//				var logininfo = JSON.parse(localStorage.logininfo) ;
//					this.searchLoading = true;
//					this.axios.get(this.$store.state.api + 'jssjd/mc',{
//							params:{
//									jsid:this.vjsid
//							}
//					}).then( res => {
//						console.log(12)
//							console.log(res)
//							// this.sjdboxlist = res;
//							let data = res.data.data;
//							this.sjdboxlist = data;
//					}).catch( res => {
//					})
			},
			submit() {

				var arr = ''+this.checkList;
				// alert(arr)
				var hstr='';
				// alert(arr.indexOf('4'))
				if(arr.indexOf('1')!=-1 && (this.vsjdid1.length)>0 ){
					hstr+='1:'+this.vsjdid1 +';';
				}
				if(arr.indexOf('2')!=-1&& this.vsjdid2.length>0  ){
					hstr+='2:'+this.vsjdid2 +';';
				}
				if(arr.indexOf('3')!=-1 && this.vsjdid3.length>0  ){
					hstr+='3:'+this.vsjdid3 +';';
				}
				if(arr.indexOf('4')!=-1 && this.vsjdid4.length>0  ){
					hstr+='4:'+this.vsjdid4 +';';
				}
				if(arr.indexOf('5')!=-1 && this.vsjdid5.length>0  ){
					hstr+='5:'+this.vsjdid5 +';';
				}if(arr.indexOf('6')!=-1 && this.vsjdid6.length>0  ){
					hstr+='6:'+this.vsjdid6 +';';
				}if(arr.indexOf('0')!=-1 && this.vsjdid7.length>0  ){
					hstr+='0:'+this.vsjdid7 +';';
				}
//				alert(hstr)
				//检测
					if(this.vkssj){
						var time1 = this.$.getLocalTimeNo0(Date.parse(this.vkssj));
					}else{
						var time1 = this.vkssj
					}
					this.$store.state.loading = true;
				   /* if(!this.mc) {
						this.$message.warning('请填写分类名称');
						this.$store.state.loading = false;
						return;
					} */
					var logininfo = JSON.parse(localStorage.logininfo);
					var params3 = qs.stringify({
						yhid:logininfo.id,
						bjid:this.vbjid,
						jsid:this.vjsid,
						lsid:this.vlsid,
						kscnt:this.vkssl,
						bjtime:time1,
						xxid:logininfo.xxid,

						sjdid:hstr,
						weekstr:1+'',
							// kcid:this.vkcid,
					});
					//执行
					this.axios.post(this.$store.state.api + 'pk/Pkplpk', params3)
						.then(res => {
							if(res.data.code == 1) {
								this.$emit('close', { type: 'add', cancel: false });
								this.$store.state.loading = false;
							} else {
								this.$emit('close', { type: 'add', cancel: false });
								this.$store.state.loading = false;
							}
						}).catch(res => {
							this.$message.warning("服务器繁忙，请重试");
							//this.$emit('close', { type: 'add', cancel: false });
							this.$store.state.loading = false;
						})

			},



			cancel() {
				this.$emit('close', { type: 'add', cancel: true })
			},
			componentsShow (type,data) { //显示组件
                console.log(type,data)
                for ( let i in this.portComponents ) {
                    if (type == this.portComponents[i].type) {
                        this.portComponents[i].toggle = true;
                        this.portComponents[i].params = data;
                        if (this.portComponents[i].data.type == 'single') {
                            this.portComponents[i].data.index = data.row.id
                        }else if(this.portComponents[i].data.type == 'multiple'){
                            this.portComponents[i].data.index = this.multipleDelNum;
                        }else{
                            return;
                        }
                        return;
                    }
                }
            },
		}
	}
</script>
<style lang="less" scoped>
.wrap {
	text-align: center;
}
.bt{
		position: absolute;
		width: 100%;
		height: 50px;
		margin: 0 auto;
		top: 0;
		left: 0;
		background: #50BFFF;
		color:white;
		text-align:left;
		line-height: 50px;
		font-size: 17px;
		padding-left: 15px;
	}

.form {
	text-align: left;
}
 .input {
					width: 300px;
					display: inline-block;
			}

.select-block {
	// display: block;
	float: left;
	width: 75%;
}

.submit {
	width: 120px;
}
</style>
